package yrl.list;

import java.util.ArrayList;
import java.util.ListIterator;

public class ListIteratorDemo {
	//ListIterator提供了一种逆向遍历的函数
	static ArrayList<String> init() {
		ArrayList<String> list = new ArrayList<>();
		list.add("Jack");
		list.add("Jone");
		list.add("Mark");
		return list;
	}
	static void reverseEnumElement(ArrayList<String> list) {
		ListIterator<String> listIterator=list.listIterator(list.size());/*加list.size()参数将指针放到
		 																  *不加则开始指针在列表头，前面无元素*/
		while(listIterator.hasNext()) {          //正向遍历
			System.out.print(listIterator.next()+" ");
		}
		
		while(listIterator.hasPrevious()) {//逆向遍历
			System.out.print(listIterator.previous()+" ");
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<String> list=init();
		reverseEnumElement(list);	
	}

}
